package com.whw.fy.controller;

import com.whw.fy.config.GlobalConfig;
import com.whw.fy.entity.Message;
import com.whw.fy.utils.GlobalFileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/api/file")
@Api(tags = "全局文件上传模块")
public class GlobalFileController {

    @Resource
    private GlobalConfig config;

    /**
     * @Author: Wls
     * @Date: 17:50 2020/4/7
     * @Description: 全局文件上传接口
     */
    @PostMapping("/")
    @ApiOperation(value = "文件上传，返回文件名数组")
    public Message fileUpload(MultipartFile[] files) throws IOException {
        if (files.length>0) {
            String rs=GlobalFileUtils.saveFileToTempDir(config.globalFilePath,config.hostUrl,files);
            return Message.success(null).add(rs);

        }
        return Message.fail("没有读取到您的上传文件信息");
    }


}
